<?php

declare(strict_types=1);

namespace App\Repository;
/**
 * 用户文章关联关系数据访问层
 * 作者 薛原
 * 日期 2025-10-17
 */
use App\Model\Articles;
use App\Model\UserFollows;
use Hyperf\Di\Annotation\Inject;

class UserArticleRepository
{
    #[Inject]
    private UserFollows $userFollows;
    #[Inject]
    private Articles $article;

    /**
     * 用户文章统计
     * @param $user_id
     * @return int
     */
    public function getArticleCount($user_id): int
    {
        return $this->article->where("user_id",$user_id)->count();
    }

    /**
     * 用户关注数统计
     * @param $user_id
     * @return int
     */
    public function getUserFollowerCount($user_id): int
    {
        return $this->userFollows->where("follower_id",$user_id)->count();
    }

    /**
     * 用户被关注数统计
     * @param $user_id
     * @return int
     */
    public function getUserFolloweringCount($user_id): int
    {
        return $this->userFollows->where("following_id",$user_id)->count();
    }

    /**
     * 用户文章被浏览次数统计
     * @param $user_id
     * @return int
     */
    public function getUserArticleViewCount($user_id): int
    {
        return $this->article->where("user_id",$user_id)->sum("view_count");
    }
}